package com.lecloud.playerdemo.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.Toast;

import com.lecloud.lecloudsdkdemo2.R;
import com.lecloud.playerdemo.MApplication;
import com.lecloud.sdk.constant.PlayerParams;

public class ActionActivity extends Activity implements OnClickListener {
	boolean hasSkin;
	String mActiveId = "A2017022300000bd";

	private String mPU = "0";
	private ImageView back;
	private TextView mTitle;
	private Button mStartActive;
	private RadioButton mRtmp;
	private RadioButton mHls;
	private EditText mActiveIdContent;
	private EditText mActivePuContent;
	private CheckBox checkBoxPano;

	private EditText mCuidContent;
	private EditText mTokenContent;

	@Override
	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_action);
		hasSkin = getIntent().getBooleanExtra("hasSkin", false);
		initView();
		setOnClickListener();
		mRtmp.setChecked(true);
		mHls.setChecked(false);

	}

	private void setOnClickListener() {

		back.setOnClickListener(this);
		mStartActive.setOnClickListener(this);
	}

	private void initView() {

		mActiveIdContent = (EditText) findViewById(R.id.active_content);
		mActiveIdContent.setText(mActiveId);

		mRtmp = (RadioButton) findViewById(R.id.rtmp);
		mHls = (RadioButton) findViewById(R.id.hls);
		mStartActive = (Button) findViewById(R.id.startActive);
		back = (ImageView) findViewById(R.id.back);
		mTitle = (TextView) findViewById(R.id.title);
		checkBoxPano = (CheckBox) findViewById(R.id.pano);
		mActivePuContent = (EditText) findViewById(R.id.activePu_content);
		mActivePuContent.setText(mPU);
		if (hasSkin) {
			mTitle.setText(getResources().getString(R.string.live_hasSkin));
		} else {
			mTitle.setText(getResources().getString(R.string.live_noSkin));
		}
		mCuidContent = (EditText) findViewById(R.id.cuid_content);
		mCuidContent.setText("");
		mTokenContent = (EditText) findViewById(R.id.token_content);
		mTokenContent.setText("");
	}

	@Override
	protected void onDestroy() {

		super.onDestroy();
	}

	@Override
	public void onClick(View v) {

		switch (v.getId()) {
		case R.id.back: {
			ActionActivity.this.finish();
			break;
		}
		case R.id.startActive: {
			if (!MApplication.cdeInitSuccess) {
				Toast.makeText(this, "CDE未初始化完成,不能播放...", Toast.LENGTH_SHORT)
						.show();
				return;
			}
			startLeCloudActionLive();
			break;
		}
		case R.id.rtmp: {
			mRtmp.setChecked(true);
			mHls.setChecked(false);
			break;
		}
		case R.id.hls: {
			mRtmp.setChecked(false);
			mHls.setChecked(true);
			break;
		}
		default:
			break;
		}
	}

	// 乐视云活动直播
	private void startLeCloudActionLive() {

		Intent intent = new Intent(ActionActivity.this, PlayActivity.class);
		Bundle mBundle = new Bundle();

		mBundle.putInt(PlayerParams.KEY_PLAY_MODE,PlayerParams.VALUE_PLAYER_ACTION_LIVE);
		mBundle.putString(PlayerParams.KEY_PLAY_ACTIONID, mActiveIdContent.getText().toString().trim());
		mBundle.putString(PlayerParams.KEY_PLAY_PU, mActivePuContent.getText().toString().trim());
		mBundle.putBoolean(PlayerParams.KEY_PLAY_USEHLS, mHls.isChecked());
		// mBundle.putString(PlayerParams.KEY_ACTION_CUID, "1");
		// mBundle.putString(PlayerParams.KEY_ACTION_UTOKEN, "22");
		mBundle.putString(PlayerParams.KEY_CUID, mCuidContent.getText().toString().trim());
		mBundle.putString(PlayerParams.KEY_UTOKEN, mTokenContent.getText().toString().trim());
		mBundle.putBoolean("pano", checkBoxPano.isChecked());
		mBundle.putBoolean("hasSkin", hasSkin);

		intent.putExtra(PlayActivity.DATA, mBundle);
		startActivity(intent);
	}

}
